package com.yoki.cloud.common.protocol.radius.msg.packet.check.resp;


import com.yoki.cloud.common.protocol.radius.attribute.attr.check.*;
import com.yoki.cloud.common.protocol.radius.msg.packet.RadiusMsg;
import com.yoki.cloud.common.protocol.radius.msg.packet.RespRadiusMsg;

/**
 * @author Sky$
 * @Description: TODO
 * @date 2018/1/12$ 9:32$
 */
public class AccessAcceptMsg extends RespRadiusMsg {

    public static final int PACKET_CODE = 2;

    public AccessAcceptMsg(String secret, RadiusMsg reqMsg) {
        super(secret, reqMsg);
        code = getPacketCode() ;
    }

    @Override
    public int getPacketCode() {
        return PACKET_CODE;
    }

    @Override
    protected boolean typeLegal(int type , boolean print) {
        if ((type == UserPasswordAttr.ATTR_TYPE) || (type == ChapPasswordAttr.ATTR_TYPE)
                || (type == NasIpAddressAttr.ATTR_TYPE) || (type == NasPortAttr.ATTR_TYPE)
                || (type == CalledStationIdAttr.ATTR_TYPE) || (type == CallingStationIdAttr.ATTR_TYPE)
                || (type == NasIdentifierAttr.ATTR_TYPE) || (type == ChapChallengeAttr.ATTR_TYPE)
                || (type == NasPortTypeAttr.ATTR_TYPE)) {
            if(print) {
                System.out.println("Data can not be converted into this type of attribution , Type is inconsistent !!! " +
                        "Radius Access-Accept packet required type can not be [ "
                        + UserPasswordAttr.ATTR_TYPE + " , " + ChapPasswordAttr.ATTR_TYPE + " , "
                        + NasIpAddressAttr.ATTR_TYPE + " , " + NasPortAttr.ATTR_TYPE + " , "
                        + CalledStationIdAttr.ATTR_TYPE + " , " + CallingStationIdAttr.ATTR_TYPE + " , "
                        + NasIdentifierAttr.ATTR_TYPE + " , " + ChapChallengeAttr.ATTR_TYPE + " , "
                        + NasPortTypeAttr.ATTR_TYPE
                        + " ]");
            }
            return false;
        }
        return true;
    }
}
